package com.homework11;
import java.io.*;
import java.util.Collections;
import java.util.HashSet;

public class demo {
    public static void main(String[] args) throws Exception{
        HashSet<Student> students = new HashSet<>();//存放学生
        Student student1 = new Student("lisi1", 20, "boy");
        Student student2= new Student("lisi2", 21, "girl");
        Student student3= new Student("lisi3", 22, "boy");
        Collections.addAll(students,student1,student2,student3);
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream("D:\\STU2.txt"));
        objectOutputStream.writeObject(students);
        objectOutputStream.close();
        ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream("D:\\STU2.txt"));
        HashSet<Student> s=( HashSet<Student>)objectInputStream.readObject();
        for (Student student : s) {
            System.out.println(student.getName()+"--"+student.getAge()+"--"+student.getSex());
        }

    }
}
